/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.xuexiang.xui_lib.component.edittext.materialedittext;

import java.util.HashMap;

/**
 * ColorStateList
 *
 * @since 2021-03-24
 */
public class ColorStateList {
    HashMap<Integer, Integer> colorStateList = new HashMap<>();
    int defaultColor = 0;

    /**
     * addState
     *
     * @param states
     * @param color
     */
    public void addState(int[] states, int color) {
        if (states != null && states.length > 0) {
            for (int i1 = 0; i1 < states.length; i1++) {
                colorStateList.put(states[i1], color);
            }
        }
        if (states != null && states.length == 0) {
            defaultColor = 0;
        }
    }

    /**
     * getColorForState
     *
     * @param states
     * @param color
     * @return int
     */
    public int getColorForState(int[] states, int color) {
        if (states != null && states.length > 0) {
            for (int i1 = 0; i1 < states.length; i1++) {
                if (colorStateList.get(states[i1]) != null) {
                    return colorStateList.get(states[i1]);
                }
            }
        }
        if (states != null && states.length == 0) {
            return defaultColor;
        }
        return color;
    }
}
